/*************************************************************************
 *  Copyright © 2023-2030 FXB CO.,LTD. All rights reserved.
 *------------------------------------------------------------------------
 *  公司：DefaultCompany
 *  项目：UPMProject3
 *  文件：PackageInspectorInfoEditor.cs
 *  作者：Administrator
 *  日期：2025/3/6 21:18:18
 *  功能：Nothing
*************************************************************************/

using SVNPackageManager.Runtime;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace SVNPackageManager.Editor
{
    [CustomEditor(typeof(PackageInspectorInfo))]
    public class PackageInspectorInfoEditor : UnityEditor.Editor
    {
        PackageInspectorInfo inspectorInfo { get { return target as PackageInspectorInfo; } }

        private void OnEnable()
        {
            finishedDefaultHeaderGUI += DisplayGUIDIfPersistent;
        }

        void DisplayGUIDIfPersistent(UnityEditor.Editor editor)
        { 
            EditorGUILayout.LabelField($"Package \'{inspectorInfo.packageConfig.displayName}\' Manifest");
        }

        private void OnDestroy()
        {
            finishedDefaultHeaderGUI -= DisplayGUIDIfPersistent;
        }


        public override void OnInspectorGUI()
        {

            EditorGUILayout.LabelField("Infomation",new GUIStyle("label") {fontStyle = FontStyle.Bold });
            EditorGUILayout.Space(5);
            EditorGUILayout.TextField("Name", inspectorInfo.packageConfig.name);
            EditorGUILayout.TextField("Display Name", inspectorInfo.packageConfig.displayName);
            EditorGUILayout.TextField("Version", inspectorInfo.packageConfig.version);
            EditorGUILayout.TextField("Categoty", inspectorInfo.packageConfig.categoty);
            EditorGUILayout.Space(5);
            EditorGUILayout.LabelField("Description", new GUIStyle("label") { fontStyle = FontStyle.Bold });
            EditorGUILayout.Space(5);
            EditorGUILayout.TextArea(inspectorInfo.packageConfig.description,GUILayout.Height(100));
            EditorGUILayout.Space(5);
            EditorGUILayout.LabelField("Dependencis", new GUIStyle("label") { fontStyle = FontStyle.Bold });
            EditorGUILayout.Space(5);

            //GUILayout.Box("",GUILayout.Width(200),GUILayout.Height(100));

            using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox))
            {
                GUILayout.Label("Package name", GUILayout.Width(200));
                GUILayout.Label("Version", GUILayout.Width(100));
            }

            List<Dependency> dependencies = inspectorInfo.packageConfig.Dependencies;

            using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox))
            {
                if (dependencies == null || dependencies.Count == 0)
                {
                    GUILayout.Label("List is Empty");
                }
                else
                {
                    foreach (var dependency in inspectorInfo.packageConfig.Dependencies)
                    {
                        GUILayout.Label(dependency.name, GUILayout.Width(200));
                        GUILayout.Label(dependency.version, GUILayout.Width(100));
                    }
                }
            }
        }
    }
}


